/**
 * related to repayDetail.ui
 * 
 * @Author : 2037630@163.com
 * @Timestamp : 2017-04-19
 */
var nf = sm("do_Notification");
var app = sm("do_App");
var page = sm("do_Page");
var Controller = require("core/controller");
var log = require("util/log")
var navigate = require("util/navigate")
var router = require("config/router")
var net = require("util/net");
var server = require('config/server')
var filter = require('util/filter')

Controller({	
	config:{
		name : "repayDetail",
		header:{
			title:"还款明细"
		}
	},
	name : 'index',
	mapping : {
		/**
		 * rpde_restMoney  剩余还款金额
		 * rpde_rpedMny  已还金额
		 * rpde_proName  产品名称
		 * rpde_caseNumb  案件编号
		 * rpde_sdMoney   应还本金
		 * rpde_sdItrest 应还利息
		 * 分期服务费rpde_sdFee
		 * 
		 * 
		 * rpde_listview  lsist
		 */
		"rpde_restMoney.text":"rpdetail.rpde_restMoney",
		"rpde_rpedMny.text":"rpdetail.cupoPaynum",
		"rpde_proName.text":"rpdetail.productName",
		"rpde_caseNumb.text":"rpdetail.caseCode",
		"rpde_sdMoney.text":"rpdetail.princial",
		"rpde_sdItrest.text":"rpdetail.interest",
		"rpde_sdFee.text":"rpdetail.rpde_sdFee",

		"rpde_listview":"rplist"
	},
	data : {
		rpdetail:{
			rpde_restMoney:"",
			cupoPaynum:"",
			productName:"",
			caseCode:"",
			princial:"暂无",
			interest:"",
			rpde_sdFee:"",
			
		},
		rplist : [{
			"reda_numb" : "1、",
			"lastPayAmount" : "",
			"reda_state" : "暂无",
			"lastPayDate" : ""
		}
		],
		rapList:[],
		rapBaseInfo:[],
		repAready:[]
	},
	event : {

	},
	ui:{
		repay_Label:"repay_Label"
	},
	methods : {
		getRepDetail: function (rdpaya) {
//			log.info(88888888888,rdpaya,999999)	
			net.send({
				server:server.organization.getOrderPaymentInfo,
				data:{
					orderNum:rdpaya.orderNum.cupoOrdernum
				},
				success:function(redata){	
					log.info(88888888888,redata,999999)
					this.data.rapBaseInfo.push({productName:redata.productName,
						caseCode:redata.caseCode,princial:"暂无",interest:"暂无",rpde_sdFee:"暂无"})
					this.data.rapList.push({reda_numb:"1、",lastPayAmount:redata.lastPayAmount.toFixed(2),
						reda_state:"暂无",lastPayDate:redata.lastPayDate})
					var list =this.data.rapBaseInfo[0]
					this.data.rpdetail=list
					this.data.rplist=this.data.rapList
					this.refresh('rpde_listview')
					this.refresh('$')
				},
				error : function(data) {
				},
				scope:this
			})
		},
		getCaseRepay: function (rdpaya) {
			net.send({
				server:server.organization.getCaseInfo,
				data:{
					cupoId:rdpaya.orderNum.cupoId
				},
				success:function(redata){	
					log.info(4577,redata,999999)
					if (redata.cupoStatus==59) {
						this.ui.repay_Label.text="剩余提前结清总额"
						this.data.repAready.push({rpde_restMoney:(redata.cupoEarlymoney-redata.cupoPaynum).toFixed(2),
						cupoPaynum:redata.cupoPaynum.toFixed(2)})
					}else{
						this.ui.repay_Label.text="剩余逾期还款总额"
						this.data.repAready.push({rpde_restMoney:(redata.cupoAmt-redata.cupoPaynum).toFixed(2),
							cupoPaynum:redata.cupoPaynum.toFixed(2)})
					}
					var list =this.data.repAready[0]
					this.data.rpdetail=list
					this.refresh('$')
				},
				error : function(data) {
				},
				scope:this
			})
		}
//		openAddRecord:function(folred){
//			navigate.redirectTo({getCaseInfo
//				view:router.follow.addFollow,
//				data:{
//					folred:folred[0]
//				},
//				back:function(data){
//					232323
//				}
//			})
//		},
//		toFollowInfo : function(id, data) {
//			navigate.redirectTo({
//				view : router.follow.followItem,
//				data : {
////					设置要发送的数据
////					current: data
//				},
//				back : function(data) {
//					232323
//				}
//			})
//		}
	},
	loaded : function(data) {
		this.data.datarpDetail=data
		log.info(1234,this.data.datarpDetail)
		this.getCaseRepay(this.data.datarpDetail)
		this.getRepDetail(this.data.datarpDetail)
	}
})